package tech.mobi.child.service;


import org.mymmsc.android.app.util.AndroidXmlParser;
import org.mymmsc.android.app.util.XmlResult;
import org.mymmsc.api.http.HttpClient;

import tech.mobi.child.utils.Configuration;

public class UpdateVersionService {
	public static XmlResult update(String appName, String appVersion) {

		String domain = Configuration.URL + Configuration.PROJECTNAME + "/servlet/UpdateServlet";
		XmlResult ret = null;
		AndroidXmlParser xp = null;
		String strXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
		strXML += "<mobile><request>";
		strXML += "<action>update</action>";
		strXML += "<mobileType>" + Configuration.APP_FLAG + "</mobileType>";
		strXML += "<appname>" + appName.trim() + "</appname>";
		strXML += "<version>" + appVersion.trim() + "</version>";
		strXML += "</request></mobile>";
		String msg = "";
		msg = HttpClient.PostXml(domain, strXML, Configuration.CLIENTINFO, "utf-8",
				Configuration.EXP_TIMEOUT);

		if (msg != null) {
			xp = new AndroidXmlParser(msg);
			try {
				ret = (XmlResult) xp.valueOf("response", XmlResult.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (ret == null)
			ret = new XmlResult();
		return ret;
	}
}
